/**
 *
 */
package de.cbf.cam.dsa.rcp.model.entities.items;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;

import de.cbf.util.uuidheader.entities.UUIDHeader;
import de.cbf.util.uuidheader.exceptions.EntityMergeException;

/**
 * @author salter
 *
 */
public class ItemForProfessionTypical extends ItemForProfession{

	@XmlElementWrapper(name="resolveAttributes")
	@XmlElement(name="attribute")
	protected List<String> resolveAttributes;

	/**
	 *
	 */
	public ItemForProfessionTypical() {
		super();
	}

	protected void init() {
		super.init();
		resolveAttributes = new ArrayList<String>();
	}

	@Override
	protected void doMergeDataFrom(UUIDHeader entity, boolean i_am_older)
			throws EntityMergeException {
		super.doMergeDataFrom(entity, i_am_older);
		if (entity instanceof ItemForProfessionTypical) {
			ItemForProfessionTypical other = (ItemForProfessionTypical) entity;
			if(i_am_older){
				this.resolveAttributes.clear();
				this.resolveAttributes.addAll(other.resolveAttributes);
			}
		}else{
			String mergeEntityClass = entity == null? "null":entity.getClass().getName();
			String errorMsg ="EntityToMerge "+mergeEntityClass+" does not fit class:"+this.getClass().getName();
			throw new EntityMergeException(errorMsg);
		}
	}

	public List<String> getResolveAttributes() {
		return resolveAttributes;
	}

	public void addResolveAttribute(String attribute){
		resolveAttributes.add(attribute);
	}

	public void removeResolveAttribute(String attribute){
		resolveAttributes.remove(attribute);
	}

	public void setResolveAttributes(List<String> resolveAttributes) {
		this.resolveAttributes = resolveAttributes;
	}
}
